//package com.collabarative.servlets;

import com.collabarative1.connectionUtils.ConnectionFactory;
import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.*;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

//import com.collabarative.connectionUtils.ConnectionFactory;
@WebServlet(name = "StudentRegistrationServlet", urlPatterns = {"/StudentRegistrationServlet"})
public class StudentRegistrationServlet extends HttpServlet {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
    private Object Firstname;
    private int i;

	@Override
	protected void service(HttpServletRequest req, HttpServletResponse res)
			throws ServletException, IOException {
        int i=0;
        ConnectionFactory c=new ConnectionFactory();
res.setContentType("text/html");         
String Firstname="s"+req.getParameter("First name");
//Statement st=null;
  		
String lastname	=req.getParameter("last name");
 String dob=req.getParameter("Date of Birth");
 String Gender=req.getParameter("Gender");
 char ch=Gender.charAt(0);
String Address=req.getParameter("Address");
String  Course=req.getParameter("Course");
String s=req.getParameter("Phone number");
long Phonenumber=Long.parseLong(s);
String mail=req.getParameter("E-Mai id");
String password=req.getParameter("password");
//	Connection con=ConnectionFactory.getConnection();

	
//	String sql="insert into UserDB values(?,?,?,?,?,?,?,?);";

//		st=con.prepareStatement(sql);
//		st.setString(1, Firstname);
//		st.setString(2,lastname);
//		st.setString(3, dob);
//		st.setString(4,Gender );
//		st.setString(5, Address);
//		st.setString(6, Course);
//		st.setInt(7, Phonenumber);
//		st.setString(8, mail);
//		
//	
try{
    Connection con=c.getConnection();//DriverManager.getConnection("jdbc:Odbc:oradsn","system","system");
Statement st=con.createStatement();
  
	
	String sql="insert into userDB values('"+Firstname+"','"+lastname+"','"+dob+"','"+ch+"','"+Address+"','"+Course+"',"+Phonenumber+",'"+mail+"','"+password+"')";
	//st=con.createStatement();
	//int i=0;
	i=st.executeUpdate(sql);
	st.close();
	con.close();
	} catch (Exception e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	RequestDispatcher rd=req.getRequestDispatcher("/index.jsp");//null;   //req.getRequestDispatcher("/Stuent");
boolean b;
	
	if(i==1)
	{
		b=true;
	req.setAttribute("status", b);
	req.setAttribute("uname", Firstname);
	
	}
	
	else
	{
	 b=false;
	req.setAttribute("status", b);
	}
	 rd.forward(req,res)	;
	
	}

}
